<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\FriendshipLink;
use App\Http\Requests\FriendshipLink\Store;

class FriendshipLinkController extends Controller
{
    //
    public function index()
    {
        $data   = FriendshipLink::withTrashed()->orderBy('sort')->get();
        $assign = compact('data');

        return view('admin.friendshipLink.index', $assign);
    }
    public function create()
    {
        //
        return view('admin.friendshipLink.create');
    }
    public function store(Store $request)
    {
        FriendshipLink::create($request->except('_token','q'));

        return redirect(url('admin/friendshipLink'));
    }
    
    public function edit(FriendshipLink $friendshipLink)
    {
    	$data=$friendshipLink;
         $assign = compact('data');
        return view('admin.friendshipLink.edit', $assign);
    }
    public function update(Request $request, FriendshipLink $friendshipLink)
    {
    	
      $friendshipLink->update($request->except('_token','q'));

        return redirect(url('admin/friendshipLink'));
    }
    public function destroy($id)
    {
        FriendshipLink::destroy($id);

        return redirect(url('admin/friendshipLink'));
      
    }
    //恢复删除
    public function restore($id)
    {
        FriendshipLink::onlyTrashed()->find($id)->restore();

        return redirect(url('admin/friendshipLink'));
    }
//彻底删除
    public function forceDelete($id)
    {
        FriendshipLink::onlyTrashed()->find($id)->forceDelete();

        return redirect(url('admin/friendshipLink'));
    }
    public function sort(Request $request, FriendshipLink $friendshipLinkModel)
    {
        $data     = $request->except('_token');
        $sortData = [];
        foreach ($data as $k => $v) {
            $sortData[] = [
                'id'   => $k,
                'sort' => $v,
            ];
        }
        $friendshipLinkModel->updateBatch('categories',$sortData);

        return redirect()->back();
    }

}
